package ${pkg};

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.blue.jdbc.Page;

import ${messagePkg}.${clazz}Request;
import ${messagePkg}.${clazz}Response;
import ${modelPkg}.${clazz};

/**
 * ${name}转换器
 * 
 * @author 代码由 blue-code 框架生成
 * @since 1.0 ${.now?string("yyyy年MM月dd日")}
 */
public class ${clazz}Convertor
{
	private ${clazz}Convertor()
	{
	}
	
	public static ${clazz} to${clazz}(${clazz}Request request)
	{
		if (request == null)
			return null;
		
		${clazz} ${field} = new ${clazz}();
		<#if idList??>
		<#list idList as vo>
		${field}.${vo.setter}(request.${vo.getter}());
		</#list>
		</#if>
		<#if columnList??>
		<#list columnList as vo>
		${field}.${vo.setter}(request.${vo.getter}());
		</#list>
		</#if>
		return ${field};
	}
	
	public static List<${clazz}> to${clazz}(List<${clazz}Request> requestList)
	{
		List<${clazz}> list = new ArrayList<>();
		if (requestList == null || requestList.isEmpty())
			return list;
		
		for (${clazz}Request request : requestList)
		{
			list.add(to${clazz}(request));
		}
		return list;
	}
	
	public static ${clazz}Response toResponse(${clazz} ${field})
	{
		if (${field} == null)
			return null;
		
		${clazz}Response response = new ${clazz}Response();
		<#if idList??>
		<#list idList as vo>
		response.${vo.setter}(${field}.${vo.getter}());
		</#list>
		</#if>
		<#if columnList??>
		<#list columnList as vo>
		response.${vo.setter}(${field}.${vo.getter}());
		</#list>
		</#if>
		return response;
	}
	
	public static List<${clazz}Response> toResponse(List<${clazz}> list)
	{
		List<${clazz}Response> responseList = new ArrayList<>();
		if (list == null || list.isEmpty())
			return responseList;
		
		for (${clazz} ${field} : list)
		{
			responseList.add(toResponse(${field}));
		}
		return responseList;
	}
	
	public static Map<Integer, ${clazz}Response> toResponse(Map<Integer, ${clazz}> map)
	{
		Map<Integer, ${clazz}Response> responseMap = new HashMap<>();
		if (map == null || map.isEmpty())
			return responseMap;
		
		for (Map.Entry<Integer, ${clazz}> entry : map.entrySet())
		{
			responseMap.put(entry.getKey(), toResponse(entry.getValue()));
		}
		return responseMap;
	}
	
	public static Page<${clazz}Response> toResponse(Page<${clazz}> page)
	{
		if (page == null)
			return null;
		
		Page<${clazz}Response> responsePage = new Page<>();
		responsePage.setCurPage(page.getCurPage());
		responsePage.setRows(page.getRows());
		responsePage.setSize(page.getSize());
		responsePage.setStartRowNo(page.getStartRowNo());
		responsePage.setTotalPage(page.getTotalPage());
		responsePage.setObjectList(toResponse(page.getObjectList()));
		return responsePage;
	}
	
}
